
import {toast} from 'nc-lightapp-front'

export default class TempAction{
    constructor(comp){
        this.comp = comp
    }

    //入离职页签切换
    onPaneChange = (key)=>{
        const{props,action} = this.comp
        const{main,dispatch} =  props
        dispatch({
            type: 'main/update',
            payload: {
                type: key
            }
        })
        action.pubAction.getTableData(main.orgvalue,key,main.pageInfo)
    }

    //组织参照改变
    changeOrg =(value)=>{
        const{props,action} = this.comp
        const{main,dispatch,button} = props
        dispatch({
            type: 'main/update',
            payload: {
                orgvalue: value,
                pageInfo :{
                    pageIndex: 1,
                    pageSize: 10,
                    total: 0,
                    totalPage: 1
                }
            }
        }) 
        let pk_org = value.refpk
        if(pk_org){
            action.pubAction.getTableData(value,main.type,main.pageInfo)
         }
        button.setButtonVisible({
            'add': pk_org ? true:false,
            'delete': pk_org ? true:false
        })
    }

    //表格选中事件
    onTableSelected =(props,moduled,record,index,status)=>{
        if(record.selected){
            props.button.setButtonDisabled({
                'delete': false
            })
        }else{
            let flag = true
            let tableData = props.editTable.getAllRows('handitemgrid')
            for(let i=0; i<tableData.length; i++){
                if(tableData[i].selected){
                    flag = false
                    break
                }
            }
            props.button.setButtonDisabled({
                'delete': flag
            })
        }
    }

    //表格全选事件
    onTableonSelectedAll =(props, moduleId,status,length)=>{
        props.button.setButtonDisabled({
            'delete': !status
        })
    }

    //行双击事件
    onRowDoubleClick =(record,index,props,e)=>{
        const{action} = this.comp
        action.pubAction.showFormPage('browse',record.values.pk_handcond.value)
    }

    onBeforeTableEvent =(props, moduleId, key, index)=>{
        const {main} = props
        if(key.attrcode === 'memo'){
            let pk_handler = props.editTable.getValByKeyAndIndex(moduleId,index,'pk_handler').value
            if(!pk_handler){
                toast({color: 'warning',content: main.json['gx6008-000282']})
                return false
            }
        }

        return true
    }
}